<template>
	<view class="box" v-if="isShow">
		<image src="https://www.yongshantuan.cn/images/yongshan/jiantou.png" alt=""></image>
		<view>请点击此处</view>
		<view>使用默认浏览器打开</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				isShow:true
			}
		},
		onLoad(options) {
			let {
				token,
				selections
			} = options;
			if(navigator.userAgent.toLowerCase().match(/MicroMessenger/i)=="micromessenger"){
				this.isShow=true
			}else{
				this.isShow=false
				uni.request({
					url: getApp().globalData.BASE_URL+'/hc/hcOrderMerchant/platformExportXls',
					method: 'get',
					data: {
						selections
					},
					header: {
						'X-Access-Token': token,
					},
					responseType: 'arrayBuffer', //文件编码方式
					success(res) {
						let url = window.URL.createObjectURL(new Blob([res.data], {
							type: 'application/vnd.ms-excel',
						}))
						let link = document.createElement('a')
						link.style.display = 'none'
						link.href = url
						link.setAttribute('download', new Date().getTime() + '.xls')
						document.body.appendChild(link)
						link.click()
						document.body.removeChild(link); //下载完成移除元素
						window.URL.revokeObjectURL(url); //释放掉blob对象
					},
					fail(error) {
						console.log('error', error)
					}
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.box{
		background-color: rgba(0,0,0,0.55);
		height: 100vh;
		width: 100%;
		image{
			width: 35%;
			margin-left: 60%;
			margin-top: 20rpx;
		}
		view{
			margin-top: 20rpx;
			color: #fff;
			text-align: center;
			line-height: 1.5;
			font-size: 32rpx;
		}
	}
</style>
